﻿// -----------------------------------------------------------------------
// <copyright file="AccountController_Tests.cs" company="CompDJ">
//     Copyright (c) CompDJ. All rights reserved.
// </copyright>
// -----------------------------------------------------------------------

namespace CompDJ.Web.Abstractions.UnitTests
{
    using System;
    using System.IO;
    using System.Web;
    using CompDJ.Web.Abstractions;
    using FakeItEasy;
    using FluentAssertions;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using CompDJ.Web.MVC.Models;
    using CompDJ.Web.MVC.Controllers;
    using System.Web.Routing;
    using System.Web.Mvc;
    using CompDJ.Web.MVC;
    using System.Collections.Specialized;

    /// <summary>A unit test class</summary>
    [TestClass]
    public class AccountController_Tests
    {
        /// <summary>A unit test initialization method</summary>
        /// <remarks>Needed because we are using static classes for the factories</remarks>
        [TestInitialize]
        public void TestInitialize()
        {
            WebAbstractions.Factory.ResetAllFactories();
        }
        
        /// <summary>A unit test method</summary>
        [TestMethod, TestCategory("UnitTests"), TestCategory("HttpContextBase"),
        Description("HttpContextFactory.Current.Session.SessionID - Target should be expected")]
        public void AccountController_Url_ShouldNotBeNull()
        {
            //// We needed to mock the controller so we can override the IsLocalUrl method.
            var target = A.Fake<AccountController>();
            A.CallTo(() => target.IsLocalUrl(A<string>.Ignored)).Returns(false);

            LogOnModel model = new LogOnModel()
            {
                UserName = "unit",
                Password = "test",
                RememberMe = false
            };

            WebAbstractions.Factory.InitializeMock(f =>
            {
                A.CallTo(() => f.SetAuthCookie(A<string>.Ignored, A<bool>.Ignored)).DoesNothing();
            }, m =>
            {
                A.CallTo(() => m.ValidateUser(A<string>.Ignored, A<string>.Ignored)).Returns(true);
            }, null, null);


            var result = target.LogOn(model, string.Empty);

            result.Should().NotBeNull();
        }
    }
}
